﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS.Module
{
    public partial class ucArticleCateSlide : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                int cateID = int.Parse(Request.QueryString["ID"].ToString());
                rptCateDataSource(cateID);
            }
        }

        protected void rptCateDataSource(int CateID)
        {
            DataTable dtSlideProduct = new SlideBL().SelectByCategoryID(CateID);
            if (dtSlideProduct.Rows.Count > 0)
            {
                rptCate.DataSource = new cmsImagesBL().SelectBySlideID(int.Parse(dtSlideProduct.Rows[0]["SlideID"].ToString()));
                rptCate.DataBind();
            }
        }

        protected string Link(int ImageID)
        {
            string Link = "";
            cmsImagesDO objImage = new cmsImagesBL().Select(new cmsImagesDO { ImageID = ImageID});

            if (objImage.ArticleID != 0)
            {
                cmsArticleDO objArt = new cmsArticleBL().Select(new cmsArticleDO { ArticleID = objImage.ArticleID });
                Link = "/Article/" + objArt.ArticleID + "/" + FriendlyUrl(objArt.Title);
            }
            else
                Link = "#";
            return Link;
        }

        protected string Title(int ImageID)
        {
            string Title = "";
            cmsImagesDO objImage = new cmsImagesBL().Select(new cmsImagesDO { ImageID = ImageID });

            if (!string.IsNullOrEmpty(objImage.ArticleID.ToString()))
            {
                cmsArticleDO objArt = new cmsArticleBL().Select(new cmsArticleDO { ArticleID = objImage.ArticleID });
                Title = objArt.Title;
            }
            return Title;
        }
        public string FriendlyUrl(String s)
        {
            return Ultility.Change_AV(s);
;
        }
    }
}